package com.google.code.coma.gui;

import com.google.code.coma.domain.Order;
import com.google.code.coma.gui.util.ImageUtil;
import javafx.geometry.Pos;
import javafx.scene.control.Label;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.util.Callback;

/**
 * @author Dominik Strasser, dominikstr@gmail.com
 */
public class OrderCellRenderer implements Callback<ListView<Order>, ListCell<Order>> {
	@Override
	public ListCell<Order> call(ListView<Order> orderListView) {
		return new OrderCell();
	}

	static class OrderCell extends ListCell<Order> {
		@Override
		public void updateItem(Order item, boolean empty) {
			super.updateItem(item, empty);
			if (item != null) {
				BorderPane border = new BorderPane();
				border.setLeft(new ImageView(ImageUtil.getOrderImage()));
				String labelText = "";
				if (item.isFinished())
					labelText = "[FINISHED] ";
				Label label = new Label(labelText + item.getId());
				label.setAlignment(Pos.CENTER_LEFT);
				border.setCenter(label);
				setGraphic(border);
			}
		}
	}
}
